﻿@section body {
    <form class="layui-form" action="">
        <div class="mainBox" style="background-color:#fff">
            <div class="main-container">
                <div class="layui-form-item">
                    <label class="layui-form-label layui-required">客户名称:</label>
                    <div class="layui-input-block">
                        <input type="text" name="Customer" id="Customer" lay-verify="required" placeholder="请输入客户名称" autocomplete="off" class="layui-input" />
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label layui-required">发起金额:</label>
                    <div class="layui-input-block">
                        <input type="number" name="LaunchAmount" id="LaunchAmount" lay-verify="verifyDecimal" autocomplete="off" class="layui-input" value="0"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-row layui-col-space10">
                        <div class="layui-col-xs10">
                            <label class="layui-form-label layui-required">文件路径:</label>
                            <div class="layui-input-block">
                                <input type="text" name="LaunchPicUrl" id="LaunchPicUrl" lay-verify="required" placeholder="请选择" autocomplete="off" class="layui-input" readonly />
                            </div>
                        </div>
                        <div class="layui-col-xs2">
                            <button type="button" class="layui-btn layui-btn-normal" id="selectFile">选择文件</button>
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">发起备注:</label>
                    <div class="layui-input-block">
                        <textarea id="LaunchRemark" name="LaunchRemark" placeholder="请输入内容" class="layui-textarea" style="height:200px;"></textarea>
                    </div>
                </div>
            </div>
        </div>
        <div class="bottom">
            <div class="button-container">
                <button type="button" class="pear-btn pear-btn-primary pear-btn-md" lay-submit="" lay-filter="btnSaveClose" id="btnSaveClose">
                    <i class="layui-icon layui-icon-ok"></i>
                    发起
                </button>
            </div>
        </div>
    </form>
}
@section script {
    <script>
        layui.use(['form', 'view','upload'], function () {
            var layer = layui.layer
                , upload = layui.upload
                , form = layui.form
                , view = layui.view
                , $ = layui.$
                , index = parent.layer.getFrameIndex(window.name); //获取窗口索引

            form.verify({
                verifyInt: [/^([1-9]\d*|[0]{1,1})$/, "请输入零或者正整数！"],
                verifyDecimal: [/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/, "大于等于0,或者小数点后最多两位！"]
            });

            //选完文件后不自动上传
            upload.render({
                elem: '#selectFile'
                ,url: `TaskSchedulingNew_btnSaveClose_Click` //实际使用请改成服务端真实接口
                , auto: false
                //,multiple: true
                , accept: 'file'
                , acceptMime: 'image/jpg, image/png,image/gif,image/bmp,image/jpeg'
                , exts: 'jpg|png|gif|bmp|jpeg' //只允许上传压缩文件
                , size: 1024 //限制文件大小，单位 KB
                , bindAction: '#btnSaveClose'
                , before: function (obj) { //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                    top.layer.load(0, {
                        shade: [0.5, '#fff'] //0.1透明度的白色背景
                    });
                    if ($('#LaunchPicUrl').val() == '') {
                        top.layer.closeAll('loading'); //关闭loading
                        throw "请选择上传文件";
                    }
                    this.data = {
                        Customer: $('#Customer').val(),
                        LaunchAmount: $('#LaunchAmount').val(),
                        LaunchRemark: $('#LaunchRemark').val(),
                        __RequestVerificationToken: document.getElementsByName("__RequestVerificationToken")[0].value
                    };
                }
                , choose: function (obj) {
                    //读取本地文件
                    obj.preview(function (index, file, result) {
                        $('#LaunchPicUrl').val(file.name)
                    });
                }
                , done: function (res) {
                    top.layer.closeAll('loading'); //关闭loading
                    if (res.codeIndex == 1) {
                        layer.msg(res.msg, {
                            offset: '15px'
                            , icon: 1
                            , time: 1000
                        });
                        //关闭窗体
                        parent.layer.close(index);
                    } else {
                        layer.msg(res.msg, {
                            offset: 't',
                            anim: 6
                        });
                    }
                   
                    @*$('#filePath').val('')
                    $('#Remark').html(res.msg)

                    //加载top窗体专用，通过Iframe中id查找对应的窗体
                    top.document.getElementById('@ViewBag.bakcView').contentWindow.btnSearchClick();*@
                }, error: function (index, upload) {
                    console.log('出错了')
                    top.layer.closeAll('loading'); //关闭loading
                }
            });
        });

        //遍历对象去值的空格
        function TrimObjToNewObj(obj) {
            for (var index in obj) {
                if (obj.hasOwnProperty(index)) {
                    obj[index] = trim(obj[index]);
                }
            }
            return obj;
        }
        function trim(str) { //删除左右两端的空格
            return str.replace(/(^\s*)|(\s*$)/g, "");
        }
    </script>
}
